#!/usr/bin/env python3

from hashlib import sha256
from os import walk
from os.path import join
from sys import argv, stderr

filelist: dict[str, str] = {}


def same(path: str):
    for dirname, _, filenames in walk(path):
        print(f"checking {dirname}...", file=stderr)
        for file in filenames:
            name = join(dirname, file)
            with open(name, "rb") as f:
                h = sha256(f.read())
                if not filelist.get(h.hexdigest()):
                    filelist[h.hexdigest()] = name
                else:
                    print(f"'{name}' '{filelist.get(h.hexdigest())}'")


if __name__ == "__main__":
    for t in argv[1:]:
        same(t)
